var a = getApp(), e = {};

Page({
    data: {
        show1: !1,
        cardData: {},
        cardMessage: {},
        loadingImg: !0,
        card_id: "",
        cardDataInfo: {
            card_statistics: {}
        },
        area_name: "",
        role_name: {},
        drawing: [],
        savebtnText: "保存名片图片",
        avatar: "",
        card_mobile: "/image/card_img_b.png",
        card_wechat: "/image/card_img_c.png",
        area_nameIcon: "/image/card_img_d.png",
        visit: "/image/card_img_a.png",
        canvasWidth: "",
        canvasHeight: "",
        showBtn: !1
    },
    onLoad: function(a) {
        console.log(a, "option");
    },
    onReady: function() {},
    onShow: function() {
        this.getCardDate();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    saveImg: function() {
        var a = this;
        wx.getImageInfo({
            src: this.data.visit,
            success: function(t) {
                console.log(t), a.setData({
                    visit: t.path
                }), e.visit = a.data.visit, wx.setStorage({
                    key: "iconFrom",
                    data: e
                });
            },
            fail: function(a) {
                console.log(a, "错误的回调1");
            }
        }), wx.getImageInfo({
            src: this.data.card_mobile,
            success: function(t) {
                console.log(t), a.setData({
                    card_mobile: t.path
                }), e.card_mobile = a.data.card_mobile, wx.setStorage({
                    key: "iconFrom",
                    data: e
                });
            },
            fail: function(a) {
                console.log(a, "错误的回调2");
            }
        }), wx.getImageInfo({
            src: this.data.card_wechat,
            success: function(t) {
                a.setData({
                    card_wechat: t.path
                }), e.card_wechat = a.data.card_wechat, wx.setStorage({
                    key: "iconFrom",
                    data: e
                });
            },
            fail: function(a) {
                console.log(a, "错误的回调3");
            }
        }), wx.getImageInfo({
            src: this.data.area_nameIcon,
            success: function(t) {
                a.setData({
                    area_nameIcon: t.path
                }), e.area_nameIcon = a.data.area_nameIcon, wx.setStorage({
                    key: "iconFrom",
                    data: e
                });
            },
            fail: function(a) {
                console.log(a, "错误的回调4");
            }
        }), wx.downloadFile({
            url: this.data.cardDataInfo.background,
            success: function(t) {
                var n = t.tempFilePath;
                a.setData({
                    "cardDataInfo.background": n
                }), e.background = t.tempFilePath, wx.setStorage({
                    key: "iconFrom",
                    data: e
                });
            },
            fail: function(a) {}
        }), wx.downloadFile({
            url: this.data.cardDataInfo.card_avatar,
            success: function(t) {
                a.setData({
                    "cardDataInfo.card_avatar": t.tempFilePath
                }), e.card_avatar = t.tempFilePath, wx.setStorage({
                    key: "iconFrom",
                    data: e
                });
            },
            fail: function(a) {
                console.log(a, "失败");
            }
        }), wx.downloadFile({
            url: this.data.cardDataInfo.min_code,
            success: function(t) {
                a.setData({
                    "cardDataInfo.min_code": t.tempFilePath
                }), e.min_code = t.tempFilePath, wx.setStorage({
                    key: "iconFrom",
                    data: e
                });
            },
            fail: function(a) {
                console.log(a, "错误的回调");
            }
        });
    },
    getCardDate: function() {
        var e = this, t = a.getNetAddresss("plugin.business-card.frontend.controllers.center.card.index");
        a._getNetWork({
            url: t,
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    var n = null;
                    0 != t.data.area_name.length && (null == t.data.area_name[3] && (t.data.area_name[3] = ""), 
                    null == t.data.has_one_card.address && (t.data.has_one_card.address = ""), n = t.data.area_name[0] + t.data.area_name[1] + t.data.area_name[2] + t.data.area_name[3] + t.data.has_one_card.address), 
                    e.setData({
                        cardData: t.data,
                        cardMessage: t.data.has_one_card,
                        role_name: t.data.role_name,
                        area_name: n,
                        card_id: t.data.has_one_card.id
                    }), e.getData();
                } else wx.showToast({
                    title: t.msg,
                    icon: "none"
                }), setTimeout(function() {
                    wx.reLaunch({
                        url: "/packageG/index/index"
                    });
                }, 2e3);
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getData: function() {
        var e = this, t = a.getNetAddresss("plugin.business-card.frontend.controllers.center.card-pic.index");
        t += "&card_id=" + this.data.card_id + "&card_type=1", a._getNetWork({
            url: t,
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    e.setData({
                        cardDataInfo: t.data,
                        role_name: t.data.role_name
                    }), e.saveImg();
                    var n = "";
                    e.data.cardData.area_name[0] && (n = e.data.cardData.area_name[0] + e.data.cardData.area_name[1] + e.data.cardData.area_name[2] + e.data.cardData.area_name[3] + e.data.cardData.has_one_card.address);
                    var o = {};
                    null == t.data.role_name.level_name && (t.data.role_name.level_name = ""), o.card_name = t.data.card_name, 
                    o.card_mobile = t.data.card_mobile, o.card_wechat = t.data.card_wechat, o.area_name = n, 
                    o.visit = "人气" + t.data.card_statistics.visit, o.card_name = t.data.card_name + "名片码", 
                    o.shop_name = "名片由【".concat(t.data.shop_name, "】生成"), o.role_name = t.data.role_name.role_name + "|" + t.data.role_name.level_name, 
                    wx.setStorage({
                        key: "info",
                        data: o
                    });
                }
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    ctiuShow: function(a) {
        var e = a.target.dataset.index || a.currentTarget.dataset.index;
        "1" == e ? this.setData({
            show1: !0
        }) : "2" == e && this.setData({
            show1: !1
        });
    },
    toPage: function(a) {
        var e = this;
        console.log(a);
        var t = a.target.dataset.url || a.currentTarget.dataset.url, n = a.target.dataset.type || a.currentTarget.dataset.type;
        wx.getStorage({
            key: "iconFrom",
            success: function(a) {
                a.data && wx.navigateTo({
                    url: "/packageB/member/business_card/" + t + "/" + t + "?card_id=" + e.data.cardMessage.id + "&type=" + n
                });
            }
        }), this.setData({
            show1: !1
        });
    },
    callMobile: function() {
        wx.makePhoneCall({
            phoneNumber: this.data.cardMessage.card_mobile,
            success: function(a) {
                console.log(a, "成功");
            },
            fail: function(a) {
                console.log(a, "失败");
            }
        });
    },
    goToCard: function() {
        wx.navigateTo({
            url: "/packageB/member/business_card/BusinessCard/BusinessCard?card_id=" + this.data.card_id + "&mark_id=" + this.data.cardMessage.id + "&mark=card"
        });
    },
    closeOperateListPopup: function() {
        this.setData({
            show1: !1
        });
    }
});